<?php

/**
 * This is the model class for table "{{program}}".
 *
 * The followings are the available columns in table '{{program}}':
 * @property integer $id
 * @property string $name
 * @property string $addedtime
 * @property string $updatetime
 * @property string $os
 * @property string $language
 * @property integer $weeklydownload
 * @property integer $totaldownload
 * @property integer $developer_id
 * @property integer $category_id
 *
 * The followings are the available model relations:
 * @property Category $category
 * @property Review[] $reviews
 * @property Screenshot[] $screenshots
 */
class Program extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Program the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{program}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, addedtime, updatetime, weeklydownload, totaldownload, developer_id, category_id', 'required'),
			array('weeklydownload, totaldownload, developer_id, category_id', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>255),
			array('os, language', 'length', 'max'=>50),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, addedtime, updatetime, os, language, weeklydownload, totaldownload, developer_id, category_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
			'reviews' => array(self::HAS_MANY, 'Review', 'program_id'),
			'screenshots' => array(self::HAS_MANY, 'Screenshot', 'program_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'addedtime' => 'Addedtime',
			'updatetime' => 'Updatetime',
			'os' => 'Os',
			'language' => 'Language',
			'weeklydownload' => 'Weeklydownload',
			'totaldownload' => 'Totaldownload',
			'developer_id' => 'Developer',
			'category_id' => 'Category',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('addedtime',$this->addedtime,true);
		$criteria->compare('updatetime',$this->updatetime,true);
		$criteria->compare('os',$this->os,true);
		$criteria->compare('language',$this->language,true);
		$criteria->compare('weeklydownload',$this->weeklydownload);
		$criteria->compare('totaldownload',$this->totaldownload);
		$criteria->compare('developer_id',$this->developer_id);
		$criteria->compare('category_id',$this->category_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}